/**
 * 
 */
package edu.rit.cs.core.services.daos.impl;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import edu.rit.cs.core.pojos.Customer;
import edu.rit.cs.core.services.daos.CustomerDAO;

/**
 * @author Abhishek Shrestha (axs1430)
 * @author Juan Saldana (jjs6109)
 * @author Victor Alvarez (vxa1557)
 */
public class CustomerDAOImpl extends GenericDAOImpl<Customer, Long>
  implements CustomerDAO {

  private static final long serialVersionUID = 1L;

  @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
  @Override
  public Customer findByUsername(String username) {
    final Criteria c = getSessionFactory().getCurrentSession()
      .createCriteria(getPersistentClass());
    c.add(Restrictions.eq("username", username));

    return (Customer) c.uniqueResult();
  }

}
